//
// Created by lihengliu on 2023/2/25.
//
#include <jni.h>
#include <string>
#include<android/log.h>
#include "include/jni_int_util.h"
#include "include/jni_list_util.h"

#define LOG_TAG "JNI_TAG"
#define  LOG_D(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)

extern "C" JNIEXPORT JNICALL jstring Java_com_hengfoxwolf_jetpackdemo_ui_home_HomeFragment_findContentFromJNI(
        JNIEnv *env,
        jobject thiz) {
    std::string hello = "Hello from C++";
    return env->NewStringUTF(hello.c_str());
}

extern "C" JNIEXPORT JNICALL jstring Java_com_hengfoxwolf_jetpackdemo_ui_home_HomeFragment_filterListFromJNI(
        JNIEnv *env,
        jobject thiz,
        jobject list) {

    JNIIntUtil intUtil;
    JNIListUtil listUtil;

    //遍历列表
    jclass origin_clazz = env->GetObjectClass(list);
    jmethodID origin_get = listUtil.createArrayListGetMethod(env, origin_clazz);
    jmethodID origin_size = listUtil.createArrayListSizeMethod(env, origin_clazz);
    jint origin_len = env->CallIntMethod(list, origin_size);

    for (jint i = 0; i < origin_len; ++i) {
        jobject target_obj = env->CallObjectMethod(list, origin_get, i);
        jint intValue = env->CallIntMethod(target_obj, intUtil.createIntegerIntValueMethod(env));
        LOG_D("value:%d",intValue);
    }

    std::string hello = "filterListFromJNI";
    return env->NewStringUTF(hello.c_str());
}
